{% extends "mall_base.html" %}
{% block title %}
<title>商城</title>
{% endblock %}

{% block content %}

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1>商品列表</h1>
            <hr>
            <div class="row">

            {% for category in category_list %}
                <div class="col-md-12">
                    <h2>{{ category.name }}</h2>
                    <hr>
                </div>
                {% for goods in goods_list %}
                {% if goods.category_id == category.id and goods.stock != 0  %}
                <div class="col-md-3">
                    <div class="thumbnail">
                        <h2>{{ goods.name }}</h2>
                        <div class="caption">
                            <h3>{{ goods.price }}￥</h3>
                            <p>{{ goods.description }}</p>
                            <p>库存为{{ goods.stock }}</p>
{#                            <button onclick="btnOperate('-')">-</button>#}
{#		                        <input id="num" value="1">#}
{#		                    <button onclick="btnOperate('+')">+</button>#}
                            <p>
                                <a href="/cart/{{ goods.id }}" class="btn btn-primary" role="button">加入购物车</a>
                                <a href="#" class="btn btn-default" role="button">查看详情</a>
                            </p>
                        </div>
                    </div>
                </div>
                {% endif %}
                {% endfor %}
            {% endfor %}
            </div>
        </div>
    </div>
</div>
    <script>
        var msg = "{{ msg }}";
            if (msg) {
                alert(msg);
            }
    </script>

{#    <script>#}
{#    function btnOperate(operate) {#}
{#        var num = document.getElementById("num");#}
{#        var goods_stock = "{{ goods.stock }}";#}
{#        if (operate == "+" ) {#}
{#            if (num.value+1 < goods_stock)#}
{#                num.value = parseInt(num.value) + 1;#}
{#        } else if (operate == "-") {#}
{#            if (num.value > 1) {#}
{#                num.value = parseInt(num.value) - 1;#}
{#            }#}
{#        }#}
{#    }#}
{#    </script>#}

{% endblock %}
